package com.example.campus.dao.table_gateway.shiro;


import com.example.campus.dao.model.Activity;
import com.example.campus.dao.model.shiro.Permission;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Set;

@Mapper
public interface PermissionMapper {
    @Insert("insert into t_sys_permission " +
            "(`name`, `code`, `url`, `order`) " +
            "VAlUES " +
            "(#{name}, #{code}, #{url}, #{order})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void addPermission(Permission permission);

    @Select("Select * from t_sys_permission")
    Set<Permission> getAllPermissions();

    @Select("Select * from t_sys_permission where id=#{id}")
    Permission getPermissionById(@Param("id") long id);

    @Update("<script>" +
            "UPDATE t_sys_permission " +
            "<set>" +
            "<if test='name != null'>`name` = #{name}, </if>"+
            "<if test='code != null'>`code` = #{code}, </if>"+
            "<if test='url != null'>`url` = #{url}, </if>"+
            "<if test='order != null'>`order` = #{order} </if>"+
            "</set>"+
            "where id = #{id}"+
            "</script>")
    void updatePermission(Permission permission);

    @Delete("delete from t_sys_permission where id = #{id}")
    void  deletePermissionById(@Param("id") long id);
}
